home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cujoct93.zip / 1110089B < prev    next >
Text File  |  1993-08-10  |  408b  |  26 lines

  1. /* stack1.c: A C implementation of a stack */
  2.  
  3. #include "stack1.h"
  4.  
  5. #define STACK_SIZE 100
  6.  
  7. static int stack[STACK_SIZE];
  8. static int stkptr = 0;
  9.  
  10. void stack_init(void)
  11. {
  12.     stkptr = 0;
  13. }
  14.  
  15. int stack_push(int x)
  16. {
  17.     return (stkptr == STACK_SIZE)
  18.       ? STACK_ERROR
  19.       : (stack[stkptr++] = x);
  20. }
  21.  
  22. int stack_pop(void)
  23. {
  24.     return (stkptr == 0) ? STACK_ERROR : stack[--stkptr];
  25. }
  26.